<template>
  <div class="page fxSettings">
    <div class="scroll-view">
      <customHeader middleTitle="设置" />
      <div class="page-body">
        <ul class="form-ul">
          <li>
            <span>当日津贴当日用</span>
            <div>
              <mt-switch
                v-model="switchValue1"
                @change="(v)=>{handleSwitch(v,'USABLE_TODAY_CONSUMER_GOLD','switchValue1')}"
              ></mt-switch>
            </div>
          </li>
          <div class="sub-text">
            开启时，消费者当天在本店消费获得的津贴，在本店当天再次消费时即可使用；
            <br />关闭时，消费者当天在本店消费获得的津贴，在本店内当天不可使用，次日消费可用；
          </div>
        </ul>
        <ul class="form-ul">
          <li>
            <span>收银台引导成为手机号会员</span>
            <div>
              <mt-switch
                v-model="switchValue2"
                @change="(v)=>{handleSwitch(v,'CASH_GUIDE_MOBILE_MEMBER','switchValue2')}"
              ></mt-switch>
            </div>
          </li>
          <div class="sub-text">
            开启后，若门店参与了返现营销活动，消费者扫码消费时将弹出弹窗引导成为手机号会员
            <span class="link" @click="preview">点击预览</span>
          </div>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from 'vue';
import customHeader from '../../components/header/header';
import { Toast, Switch } from 'mint-ui';
Vue.component(Switch.name, Switch);
export default {
  name: 'fxSettings',
  data() {
    return {
      switchValue1: false,
      switchValue2: false,
    };
  },
  methods: {
    //开关回调
    handleSwitch(v, functionId, model) {
      let param = [];
      let status = 0;
      if (this[model]) {
        status = 1;
      }
      const url = `/newapp/setting/setFunctionSwitch.do?functionId=${functionId}&state=${status}`;
      this.ajax({
        url: url,
        type: "get",
        controlLoading: false
      })
        .then(res => {
          if (res.success) {
          } else {
            this[model] = !this[model];
            Toast(res.msg);
          }
        })
        .catch((err) => {
        });
    },
    getData() {
      const url = "/newapp/setting/queryFunctionState.do";
      this.ajax({
        url: url,
        type: "get",
        controlLoading: false
      })
        .then(res => {
          if (res.success) {
            let v1 = false;
            let v2 = false;
            if (res.resultObject && res.resultObject.length > 0) {
              for (const item of res.resultObject) {
                if (item['fmId'] == "USABLE_TODAY_CONSUMER_GOLD" && item['fmStatus'] == 1) {
                  v1 = true;
                }
                if (item['fmId'] == "CASH_GUIDE_MOBILE_MEMBER" && item['fmStatus'] == 1) {
                  v2 = true;
                }
              }
            }
            this.switchValue1 = v1;
            this.switchValue2 = v2;
          } else {
            Toast(res.msg);
          }
        })
        .catch((err) => {

        });
    },
    preview() {
       this.$router.push({path:'/fxActivityRecord/list/fxSettings/preview',query:{url:"2019/12/17/15/169041576567157.jpg"}});
    }
  },
  components: {
    customHeader,
  },
  created() {
    this.getData();
  },
};
</script>
<style lang='scss' scoped>
@import "fxSettings";
</style>
